<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
use app\common\model\jeek\Category;
/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function getAdminData()
    {   
        $auid = (int)input('params.auid', 0);
        if($auid===0){
            // $where['auid'] = $auid;
           $code=0;
           
           $data='';
        }else{
            $admin = Db::name('admin')->where('id', $auid)->field('id, sh_title, level, status,statusp')->find();
            if($admin){
                $code=1;
                $data=$admin;
            }else{
                $code=0;
            
                $data='';
            }
            
        }
        return json([
            'code' => $code,
            'msg' => 'success',
            'data' => $data
        ]);
    }
    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }
    public function getHomeData()
    {
                $params=input('params.');

                $page=input('params.page',1);
                $limit=input('params.limit',15);
                $pid=input('params.pid',0);

                $auid = (int)input('params.auid', 1);
                
                if($auid===1){
                    $where['admin_id'] = $auid;
                   
                }else{
                      // 获取隐藏的产品分类ID
    $hiddenCategories = Db::name('jeek_category_hide')->where('admin_id', $auid)->column('category_id');
    // dump($auid);die();
    // 如果有隐藏的产品分类，则添加到查询条件中
    if (!empty($hiddenCategories)) {
        $where['id'] = [ 'not in', $hiddenCategories];
    }
    $where['admin_id']=['in',[1,$auid]];
                }

        $cdnUrl = config('cdn_url');
        $where['status'] = 'normal';
        $where['pid'] = intval($pid);
        $where['type'] = 'product';



// 打印查询条件
// print_r($where);die();
        $data=Category::where($where)->order('weigh desc')->order('id desc')->paginate($limit,true,['page'=>$page]);
// if($data->hasNextPage()){
//     $hasMore=true;
// }else{
//     $hasMore=false;
// }

        foreach ($data as $key => $value) {
            $data[$key]['image']=$cdnUrl.$value['image'];
        }
// dump($data['hasMore']);dump($data);die();
        return json([
            'code' => 1,
            'msg' => 'success',
            'data' => $data
        ]);
        // $this->success('请求成功', $data);
    }
}
